<?php
/**
 * @see Alinks_Factory_Interface
 */
require_once('Alinks/Factory/Interface.php');

/**
 * @see Alinks_Form
 */
require_once('Alinks/Form.php');

/**
 * Abstract class for the factory classes
 *
 * Copyright (C) 2008  Sean Hickey
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Sean Hickey <sean@headzoo.com>
 * @version $Id: Abstract.php 408 2008-07-05 14:14:41Z sean $
 * @package Alinks_Factory
 */
abstract class Alinks_Factory_Abstract implements Alinks_Factory_Interface
{
	/**
	 * The settings for this factory
	 *
	 * @var array
	 */
	protected $_settings = array();
	
	/**
	 * The name of the factory
	 *
	 * @var string
	 */
	protected $_name;
	
	/**
	 * The factory safe name
	 *
	 * @var string
	 */
	protected $_safe_name;
	
	/**
	 * The URL for the factory
	 *
	 * @var string
	 */
	protected $_url;
	
	/**
	 * A short description of the factory
	 *
	 * @var string
	 */
	protected $_description;
	
	/**
	 * The factory authors
	 *
	 * @var array
	 */
	protected $_authors = array();
	
	/**
	 * The factory version
	 *
	 * @var float
	 */
	protected $_version;
	
	/**
	 * The version of aLinks the factory is compatible with
	 *
	 * @var string
	 */
	protected $_alinks_version;
	
	/**
	 * The version of WordPress this factory is compatible with
	 *
	 * @var string
	 */
	protected $_wp_version = '2.*';
	
	/**
	 * If the factory has a settings form
	 *
	 * @var bool
	 */
	protected $_has_settings_form = false;
	
	/**
	 * If the factory has a keyphrases form
	 *
	 * @var bool
	 */
	protected $_has_keyphrases_form = true;
	
	/**
	 * Whether the factory has HTML help to place on the Help
	 * page
	 *
	 * @var bool
	 */
	protected $_has_help = false;
	
	/**
	 * Called by aLinks after the factory has been "set up"
	 *
	 * Note that this method won't be called by factories that are incompatible
	 * with this version of aLinks.
	 */
	public function init() {}
	
	/**
	 * Sets the factory settings
	 *
	 * @param array $settings The settings
	 * @return Alinks_Factory_Abstract
	 */
	public function setSettings(array $settings)
	{
		$this->_settings = $settings;
		return $this;
	}
	
	/**
	 * Returns the factory settings
	 *
	 * @return array
	 */
	public function getSettings()
	{
		return $this->_settings;
	}
	
	/**
	 * Returns the name of the factory
	 *
	 * @return string
	 */
	public function getName()
	{
		return $this->_name;
	}
	
	/**
	 * Returns the safe name of the factory
	 *
	 * Returns the name of the factory without any special characters
	 * or spaces.
	 *
	 * @return string
	 */
	public function getSafeName()
	{
		return $this->_safe_name;
	}
	
	/**
	 * Returns the URL for the factory
	 *
	 * @return string
	 */
	public function getUrl()
	{
		return $this->_url;
	}
	
	/**
	 * Returns a short description of the factory
	 *
	 * @return string
	 */
	public function getDescription()
	{
		return $this->_description;
	}
	
	/**
	 * Returns information about the creators of the factory
	 *
	 * The return value should be an array of arrays. Each of the inner
	 * arrays should contain a 'name' index with the author's name, and
	 * a 'url' index, with the author's website URL.
	 *
	 * @return array
	 */
	public function getAuthors()
	{
		return $this->_authors;
	}
	
	/**
	 * Returns the factory version
	 *
	 * @return float
	 */
	public function getVersion()
	{
		return $this->_version;
	}
	
	/**
	 * Returns which version of aLinks this factory is compatible with
	 *
	 * Returns a string that represents which versions of aLinks this factory
	 * can run under. The string can be a single version number like '1.0', which
	 * means the factory works only with aLinks 1.0, or it can contain a wildcard
	 * character like '1.*', which means it works with any version of aLinks in the
	 * 1.x branch.
	 *
	 * @return string
	 */
	public function getAlinksVersion()
	{
		return $this->_alinks_version;
	}
	
	/**
	 * Returns the version of WordPress this factory is compatible with
	 *
	 * @return string
	 */
	public function getWpVersion()
	{
		return $this->_wp_version;
	}
	
	/**
	 * Returns if the factory has a settings form
	 *
	 * @return bool
	 */
	public function hasSettingsForm()
	{
		return $this->_has_settings_form;
	}
	
	/**
	 * Returns if the factory has a keyphrases form
	 *
	 * @return bool
	 */
	public function hasKeyphrasesForm()
	{
		return $this->_has_keyphrases_form;
	}
	
	/**
	 * Returns whether the factory has help HTML to display
	 *
	 * If this method returns true, then aLinks will get the string
	 * returned by getHelp(), and display it on the Help page.
	 *
	 * @return bool
	 */
	public function hasHelp()
	{
		return $this->_has_help;
	}
	
	/**
	 * Returns the form information for the settings page
	 *
	 * @var Alinks_Form
	 */
	public function getSettingsForm()
	{
		return null;
	}
	
	/**
	 * Returns the form information for the keyphrases page
	 *
	 * @var Alinks_Form
	 */
	public function getKeyphrasesForm()
	{
		return null;
	}
	
	/**
	 * Returns HTML to display on the Help page
	 *
	 * @return string
	 */
	public function getHelp()
	{
		return null;
	}
	
	/**
	 * Returns whether this factory can run
	 *
	 * A factory would typically return false if some required settings
	 * haven't been set by the user yet. When false is returned, any
	 * keyphrases owned by this factory will be ignored.
	 *
	 * @return bool
	 */
	public function canRun()
	{
		return true;
	}
	
	/**
	 * Returns any keyphrases created by the factory
	 *
	 * If the factory creates it's own keyphrases, they should be returned
	 * by this method.
	 *
	 * @return Alinks_Keyphrase[]
	 */
	public function getKeyphrases()
	{
		return array();
	}
	
	/**
	 * Replaces a keyphrase with a link
	 *
	 * @param Alinks_Keyphrase_Interface $keyphrase The keyphrase
	 * @param Alinks_LinkBuilder_Interface $builder The link builder
	 * @return Alinks_LinkBuilder_Interface
	 */
	public abstract function parse(Alinks_Keyphrase_Interface $keyphrase, Alinks_LinkBuilder_Interface $builder);
}